using BackData;
using Domain.DTOs.Warehouse;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using Team.API.Applocation.Command.Warehouse.laneway;

namespace Team.API.Controllers
{
    /// <summary>
    /// 巷道管理控制器
    /// 提供巷道的创建、查询、更新、删除等接口
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class LanewayController : ControllerBase
    {
        private readonly IMediator _mediator;

        /// <summary>
        /// 构造函数，注入中介者组件
        /// </summary>
        /// <param name="mediator">MediatR 中介者组件，用于分发命令和查询</param>
        public LanewayController(IMediator mediator)
        {
            _mediator = mediator;
        }

        /// <summary>
        /// 创建巷道
        /// </summary>
        /// <param name="request">创建巷道的命令对象</param>
        /// <returns>包含操作结果的API响应</returns>
        [HttpPost]
        public async Task<APIResult<int>> CreateLaneway(CreateLanewayCommand request)
        {
            return await _mediator.Send(request);
        }

        /// <summary>
        /// 查询巷道列表
        /// </summary>
        /// <param name="request">查询巷道列表的命令对象</param>
        /// <returns>包含巷道DTO列表的API响应</returns>
        [HttpGet]
        public async Task<APIResult<List<LanewayDTO>>> GetLanewayList([FromQuery] GetLanewayListCommand request)
        {
            return await _mediator.Send(request);
        }

        /// <summary>
        /// 更新巷道信息
        /// </summary>
        /// <param name="request">更新巷道的命令对象</param>
        /// <returns>包含操作结果的API响应</returns>
        [HttpPut]
        public async Task<APIResult<int>> UpdateLaneway(UpdateLanewayCommand request)
        {
            return await _mediator.Send(request);
        }

        /// <summary>
        /// 删除巷道
        /// </summary>
        /// <param name="request">删除巷道的命令对象</param>
        /// <returns>包含操作结果的API响应</returns>
        [HttpDelete]
        public async Task<APIResult<int>> DeleteLaneway(DeleteLanewayCommand request)
        {
            return await _mediator.Send(request);
        }
    }
}
